This README lists the R files and data needed to replicate the figures and tables in the main text and supporting information of "Major Life Events and the Age - Partisan Stability Association".

The ANES results can be replicated using the publicly available ANES panel merged files.

The voter data cannot be provided in raw form due to privacy concerns and other data-sharing issues. For this, I have provided the code needed to preprocess the data, as well as some aggregate data to replicate the ultimate findings reported in the paper.

Please contact the author with any questions. I'm happy to answer questions and appreciate others double-checking the work.

File structure:
./code/anes_time_series/
./code/voter_file/
./data/ANES/
./data/voter_file_aggregated/
./figs/
./tables/

CODE -- to produce results in paper
by FIGURE

Main text

- Figure 2:
    : moving_analysis_anes_replication.R (predicted_prob_moving_no_controls_base.pdf)

- Figure 3:
    : table - summary_table_beforeafter_moves.R and summary_table_beforeafter_moves_sds.R
    : figure - plot_partychanges_by_move_distance.R
    (moving_changing_party_12to14_simple_noagecontrol_controlpastmovers.pdf)

- Figure 4:
    : simple_spouse_stats.R (the code to calculate data in figure) (spouses_same_party.pdf)

- Figure 5:
    : plot_dyad_models_lm.R, plot_dyad_models_glm.R
    (dyad_separation_cumulative.pdf, dyad_separation_or.pdf)

- Figure 6:
    : plot_summaries_individual_partychanges_with_adjustment_and_direction.R
    (retirement.pdf)

Supporting information
- Figure 7:
    : plot_summaries_individual_partychanges_with_adjustment_and_direction.R
    (all_movers_nonmovers_switching.pdf)

- Table 3:
    : moving_analysis_anes_replication.R
    (anes_models_with56_glm.tex)

- Figure 8:
    : plot_partychanges_by_move_distance.R
    (moving_changing_party_12to14_simple_noagecontrol_controlpastmovers_withcis.pdf)

- Figure 9:
    : plot_dyad_models_lm.R, plot_dyad_models_glm.R
    (dyad_separation2_cumulative.pdf, dyad_separation2_or_cumulative.pdf, dyad_separation2_or.pdf)

- Figure 10:
    : moving_analysis_anes_replication.R
    (predicted_prob_moving_no_controls_specificpointchange.pdf)

- Figure 11:
    : plot_summaries_individual_partychanges_with_adjustment_and_direction.R
    (relative_change_to_republican_2008to2012_comparedto_2006to2008_and_2012to2014.pdf)

- Figure 12:
    : plot_summaries_individual_partychanges_with_adjustment_and_direction.R
    (nonmovers_change_with_torepublican.pdf)

TABLES
- Table 2:
    : table - moving_analysis_anes_replication.R
    : figure - plot_summaries_individual_partychanges_with_adjustment_and_direction.R
    (anes_models_with_56_short.tex, adjust_for_movement.pdf)



DATA

# this is code to produce the data and model output used in the above scripts
# they use voter record data that cannot be shared here

    # formats individual voter records
    : format_households1.py

    # combines voter records across years
    : merge_voterYears.sh

    # links voters to others in same household
    : format_households2.py, join_householdsVoters.sh

    # summarizes voter records
    individual_partychanges_summary_withpartydirection.RData
    : summarize_individual_partychanges2.R

    # models dyads (model output and code to produce it) (uses voter record, not provided)
    dyad_party_change_models_glm_coefsonly.RData
    dyad_party_change_models_glm_coefsonly_cumulative.RData
    dyad_party_change_models_glm_coefsonly_placebo_cumulative.RData
    dyad_party_change_models_glm_placebo_coefsonly.RData
    dyad_party_change_models_lm_coefsonly_cumulative.RData
    dyad_party_change_models_lm_coefsonly_placebo_cumulative.RData
    model_dyad_party_changes_glm.R
    model_dyad_party_changes_glm_cumulative.R
    model_dyad_party_changes_glm.R
    model_dyad_party_changes_glm_cumulative.R
    model_dyad_party_changes_glm_placebo_cumulative.R
    model_dyad_party_changes_lm_cumulative.R
    model_dyad_party_changes_lm_placebo_cumulative.R
    model_dyad_party_changes_placebo_glm.R

    # raw data for before/after move table
    individual_partychanges_summary_withpartydirection_beforeaftermoves_registeredallyears_movers.RData,
    individual_partychanges_summary_withpartydirection_beforeaftermoves_registeredallyears_nonmovers.RData
    : summarize_individual_partychanges2_beforeaftermoves.R

    # zip code calculations
    calculate_and_add_zip_distances.R

    # models party change by zip code distance
    moves_distance_12to14_simple_noagecontrol_controlpastmoves_pastmoversonly.RData
    : model_party_change_by_move_distance.R
